<template>
    <div id="app">
        <router-view />
    </div>
</template>
<script>
import { getInfoApi, menuListRoleApi, authLoginApi } from '@/common/service/user';

export default {
    onLaunch: function () {
        console.log('App Launch');
        // if (!uni.getStorageSync('token')) {
        // 获取URL参数
        // let extraToken = this.$route.query.extraToken;
        // if (extraToken) {
        //     this.authLogin(extraToken);
        // } else {
        //     this.toLogin(extraToken);
        // }
		
        // }
    },
    onShow: function () {
        console.log('App Show');
    },
    onHide: function () {
        console.log('App Hide');
    },
    methods: {
        authLogin(extraToken) {
            authLoginApi({ identityToken: extraToken }).then((res) => {
                if (res.data == null) {
                    this.toLogin(extraToken);
                } else {
                    uni.setStorageSync('token', res.data);
                    this.getInfo();
                    this.getRoleAuth();
                }
            });
        },
        getInfo() {
            getInfoApi().then((res) => {
                uni.setStorageSync('USER_INFO', res.data);
            });
        },
        getRoleAuth() {
            menuListRoleApi().then((res) => {
                let role = res.data
                uni.setStorageSync('ROLE_AUTH', role);
            });
        },
        toLogin(extraToken) {
            uni.redirectTo({
                url: '/pages/login/login?extraToken=' + extraToken
            });
        }
    }
};
</script>

<style>
/*每个页面公共css */
:root,
page {
    /* 默认主题色 */
    --wot-color-theme: #2263e1;
    background: #f8f8f8;
}
</style>
<style lang="scss">
$-fs-content: 28rpx;
@import '@/static/scss/base.scss'
</style>
